#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>

const char *test_path = "/home/sc/dev/ospp/test/ovl/merge/write_once_16K";
const char *block_path = "/home/sc/dev/ospp/test/ovl/merge/block";

const off_t offset = 0xd00;

char buf[512];

int main(){
    int ret;

    int test_fd = open(test_path, O_WRONLY);
    if(test_fd < 0) {
        printf("error open test file:%s\n", strerror(errno));
        exit(EXIT_FAILURE);
    }
    
    int block_fd = open(block_path, O_RDONLY);
    if(block_fd < 0) {
        printf("error open block file:%s\n", strerror(errno));
        exit(EXIT_FAILURE);
    }
    ret = lseek(test_fd, offset, SEEK_SET);
    if(ret < 0){
        printf("lseek error: %s\n", strerror(errno));
        exit(EXIT_FAILURE);
    }
    
    while((ret = read(block_fd, buf, sizeof(buf))) > 0){
        write(test_fd, buf, sizeof(buf));
        memset(buf, 0, strlen(buf));
    }

    close(test_fd);
    close(block_fd);
}